import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nft/page/order/order_index.dart';
import 'package:flutter_nft/provider/LoginProvider.dart';
import 'package:provider/provider.dart';

import '../../api/API.dart';

class MessageIndex extends StatefulWidget {
  @override
  _MessageIndexState createState() => _MessageIndexState();
}

class _MessageIndexState extends State<MessageIndex> {

  List<OrderList?> orderLists = [];

  getOrderList() async {
    var result = await new Dio().get(API.reqUrl +
        "/get/order/list/" +
        context.read<LoginProvider>().getUserName());
    if (result.data["flag"]) {
      List<OrderList?> list = (result.data["dataObj"] as List<dynamic>)
          .map((e) => OrderList.fromMap((e as Map<String, dynamic>)))
          .toList();
      if (list.length > 0) {
        setState(() {
          orderLists = list;
        });
      }

      print(list.toString());
    }
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getOrderList();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.topLeft,
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      child: Column(
        children: [
          SizedBox(
            height: 60,
          ),
          Padding(
            padding: EdgeInsets.only(left: 15),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  //color: Colors.blue,
                  alignment: Alignment.center,
                  width: 200,
                  height: 30,
                  child: Text(
                    "我的展馆",
                    style: TextStyle(fontSize: 25, color: Colors.white),
                  ),
                ),
                SizedBox(
                  height: 10,
                ),
                Container(
                  alignment: Alignment.center,
                  width: 200,
                  height: 20,
                  child: Text(
                    "查看你的私人展馆",
                    style: TextStyle(color: Colors.white70),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: 15,
          ),
          Expanded(
            child: Padding(
              padding: EdgeInsets.only(bottom: 66),
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: 550,
                decoration: BoxDecoration(
                    color: Colors.black, borderRadius: BorderRadius.circular(16)),
                child: context.read<LoginProvider>().isLogin
                    ? ListView(
                  children: orderLists.map((e) =>e!.payStart == 2? Padding(
                    padding: EdgeInsets.only(
                        left: 10,
                        right: 10,
                        bottom: 10
                    ),
                    child: Container(
                      width: double.infinity,
                      height: 450,
                      decoration: BoxDecoration(
                        color: Color.fromRGBO(43, 44, 45, 1),
                        borderRadius: BorderRadius.circular(30),
                        gradient: LinearGradient(
                            begin: Alignment.topLeft,
                            end: Alignment.bottomLeft,
                            colors: [
                              Color.fromRGBO(50, 55, 58, 1),
                              Color.fromRGBO(43, 44, 45, 1),
                            ]),
                      ),
                      child: Stack(
                        children: [
                          GestureDetector(
                            onTap: (){
                              Navigator.of(context).pushNamed("payproductdetail",arguments: e.productCode.toString());
                              context.read<LoginProvider>().setProductDetailCode(e.productCode);
                            },
                            child: Container(
                              width: double.infinity,
                              height: 380,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(30),
                                image: DecorationImage(
                                    image: NetworkImage(e.productImage.toString()),
                                    fit: BoxFit.fill),
                              ),
                            ),
                          ),
                          Positioned(
                            top: 380,
                              bottom: 0,
                              child: Container(
                                margin: EdgeInsets.only(left: 10, top: 20),
                                width: MediaQuery.of(context).size.width,
                                height: 90,
                                decoration: BoxDecoration(borderRadius: BorderRadius.circular(90)),
                                child: Column(
                                  children: [
                                    Container(
                                      child: Row(
                                        children: [
                                          Text(
                                            e.productTitle.toString(),
                                            style: TextStyle(
                                                fontSize: 20,
                                                color: Colors.white,
                                                fontWeight: FontWeight.w600),
                                          ),
                                          SizedBox(
                                            width: 5,
                                          ),
                                          Text(
                                            "3D",
                                            style: TextStyle(
                                                fontSize: 16, color: Colors.white),
                                          ),
                                          //Icon(Icons.delivery_dining)
                                        ],
                                      ),
                                    ),
                                    SizedBox(
                                      height: 8,
                                    ),

                                  ],
                                ),
                              ))
                        ],
                      ),
                    ),
                  ):Text("")).toList(),
                )
                    : Container(
                        width: MediaQuery.of(context).size.width,
                        height: 300,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: Color.fromRGBO(42, 42, 42, 1),
                            borderRadius: BorderRadius.circular(15)),
                        child: Center(
                          child: Container(
                            width: 160,height: 200,
                            child: Column(
                              children: [
                                Text("登录古谢",style: TextStyle(fontSize: 30,color: Colors.white),),
                                SizedBox(height: 5,),
                                Text("发现有趣",style: TextStyle(fontSize: 30,color: Colors.white),),
                                SizedBox(height: 30,),
                                InkWell(
                                  onTap: (){
                                    Navigator.of(context).pushNamed("registertwo");
                                  },
                                  child: Container(
                                    width: 160,
                                      height: 50,
                                    decoration: BoxDecoration(color: Color.fromRGBO(240, 225, 192, 1),borderRadius: BorderRadius.circular(50)),
                                    child: Center(
                                      child: Text("立即登录",style: TextStyle(color: Color.fromRGBO(72, 57, 39, 1),fontSize: 22),),
                                    ),
                                  ),
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
